Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a panic in Postgres revision parsing for incompatible ZedTokens #1540

Merged
merged 1 commit into from
Sep 19, 2023

Conversation

josephschorr
Copy link
Member

If Postgres is passed a ZedToken from CRDB, it will (incorrectly) interpret the token and try to create a slice with too much capacity. This change caps the delta on the transaction IDs and returns an error in that scenario

Fixes #1539

@josephschorr josephschorr requested review from jakedt and a team September 19, 2023 19:11
@github-actions github-actions bot added area/datastore Affects the storage system area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Sep 19, 2023
@DBBrowne
Copy link

DBBrowne commented Sep 19, 2023

Are "we" sure it's a size issue, rather than an int vs float issue?

in our case, the similarly sized GhUKEzE2OTM1NDA5NDQ5NTk3MjA1OTI= does not cause the pre-change panic that GiAKHjE2OTM1NDA5NDAzNzMwNDU3MjcuMDAwMDAwMDAwMQ== does.

@jzelinskie jzelinskie added the kind/bug Something is broken or regressed label Sep 19, 2023
jzelinskie
jzelinskie previously approved these changes Sep 19, 2023
@josephschorr
Copy link
Member Author

josephschorr commented Sep 19, 2023

Yeah, its a capacity failure on trying to create a slice to track the revisions. The panic occurs on a uint64, so it cannot be a float issue

@DBBrowne
Copy link

Yeah, its a capacity failure on trying to create a slice to track the revisions. The panic occurs on a uint64, so it cannot be a float issue

The failing token GiAKHjE2OTM1NDA5NDAzNzMwNDU3MjcuMDAwMDAwMDAwMQ== decodes to \x1a \n\x1e1693540940373045727.0000000001

So if it's a size issue, we'd expect \x1a \n\x1e1693540940373045728 (GiAKHjE2OTM1NDA5NDAzNzMwNDU3Mjg=) to throw as well?

If Postgres is passed a ZedToken from CRDB, it will (incorrectly) interpret the token and try to create a slice with too much capacity. This change caps the delta on the transaction IDs and returns an error in that scenario

Fixes authzed#1539
@josephschorr
Copy link
Member Author

josephschorr commented Sep 19, 2023

So if it's a size issue, we'd expect \x1a \n\x1e1693540940373045728 (GiAKHjE2OTM1NDA5NDAzNzMwNDU3Mjg=) to throw as well?

We would, except the lack of a decimal point means that it is interpreted as size 0. This is because legacy Postgres revisions were stored as a decimal representing a range, where X.Y was a range from X->Y.

In the case of the first revision given, 1693540940373045727.0000000001 became 1693540940373045727 -> 1 for a size of 1693540940373045726. In your second example, 1693540940373045728 became 1693540940373045728->1693540940373045728, with a size of 0.

This is all because legacy Postgres revisions were stored in this particular format, and giving a CRDB revision that "just so happened" to hit the legacy parsing code perfectly

@DBBrowne
Copy link

DBBrowne commented Sep 19, 2023

Ah, interesting on the postgres history, ty.

so here the second part of the decimal timestamp is correctly being parsed as an xmin candidate, and correctly assigned to xmin on L208, as if it was a postgres revision.

it's correct then to return the error after calculating the range, not dismiss the float timestamp sooner.

thanks again!

@josephschorr josephschorr added this pull request to the merge queue Sep 19, 2023
Merged via the queue into authzed:main with commit 9214148 Sep 19, 2023
@josephschorr josephschorr deleted the zedtoken-panic-fix branch September 19, 2023 19:50
@github-actions github-actions bot locked and limited conversation to collaborators Sep 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/datastore Affects the storage system area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) kind/bug Something is broken or regressed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic on giving ZedTokens from CRDB to Postgres
4 participants